package com.cnhis.cloudhealth.clinical.hosdoctor.doctorordernew.bo;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cnhis.cloudhealth.clinical.clidoctor.cliparamter.dao.CliParamterDao;
import com.cnhis.cloudhealth.clinical.hosdoctor.doctorordernew.dao.DoctorordernewDao;
import com.cnhis.cloudhealth.clinical.hosdoctor.doctorparameter.bo.DoctorparameterBo;
import com.cnhis.cloudhealth.clinical.hosnurse.hossendadvice.bo.HosSendAdviceBo;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.newid.GetNewId;
import com.cnhis.cloudhealth.commons.utils.*;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import net.sf.json.JSONObject;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by xiezhenyuan on 2016/3/24.
 */
@Service
public class DoctorordernewBo {
    @Resource
    private DoctorordernewDao doctorordernewDao;
    @Autowired
    private GetNewId getNewId;
    @Autowired
    private DoctorparameterBo doctorparameterBo;
    @Resource
    private CliParamterDao cliParamterDao;
    @Autowired
	private HosSendAdviceBo hosSendAdvice;
    public ModelVo selectPhaveoutorder(Map map){return MySqlUtil.packModelVo("Doctorordernew.1293",map,doctorordernewDao);}
    public ModelVo selectPfeealert(Map map){return MySqlUtil.packModelVo("Doctorordernew.2042",map,doctorordernewDao);}
    public ModelVo selectLastmedhistory(Map map){
        Integer aacf01 = MapUtils.getInteger(map,"aacf01");
        if(aacf01!=null&&aacf01==1){
            return MySqlUtil.packModelVo("Doctorordernew.6434_001",map,doctorordernewDao);
        }else{
            return MySqlUtil.packModelVo("Doctorordernew.6434_002",map,doctorordernewDao);
        }
    }
    public ModelVo selectPdrugallergyrcd(Map map){return MySqlUtil.packModelVo("Doctorordernew.7282",map,doctorordernewDao);}
    public ModelVo selectPisallergy(Map map){return MySqlUtil.packModelVo("Doctorordernew.1547",map,doctorordernewDao);}

    private List<Map<String,Object>> parseJsonToList(String json,String key){
        JSONObject jo = JSONObject.fromObject(json);
        List<Map<String,Object>> list = null;
        if(jo.containsKey(key)){
            list =  JsonUtil.parserToList(jo.getJSONArray(key));
        }
        return list;
    }


    /** 快速插入医嘱（Nurse_Shortcut_Advice）
     * @param map 参数
     * @return
     */
    public ModelVo insertQuickOrder(Map map) throws Exception {
        ModelVo mo = new ModelVo();
        Integer lMode = MapUtils.getInteger(map,"lMode");   //0-出院，1-转科，2-护理 3-会诊
        Integer VCS05 = MapUtils.getInteger(map,"VCS05",0);   //退出路径
        String VCS06 =  MapUtils.getString(map,"VCS06","");   //退出路径原因
        String lXml = MapUtils.getString(map,"lXml","");     //住院诊断记录
        String lPatXml = MapUtils.getString(map,"lPatXml","");     //预出院信息记录
        Integer lBCK01 = MapUtils.getInteger(map,"lBCK01"); //开单人科室
        String lBCE01 = MapUtils.getString(map,"lBCE01"); //开单人ID
        String lBCE03 = MapUtils.getString(map,"lBCE03"); //开单人
        String lDate = MapUtils.getString(map,"lDate"); //time
        Date nowdate = new Date();
        map.put("lDateA",nowdate);
        map.put("lDate",lDate);
        List<Map<String,Object>> tmpvcl = new ArrayList<Map<String,Object>>();
        Integer lBCK01B = 0;
        if(lMode==0||(lMode==4)){
            if(lMode==4) {
                Long vcnct = (Long) doctorordernewDao.queryToObject("Doctorordernew.quickinsert_002", map);   //病人临床路径表
                if (vcnct != null && vcnct == 0) {
                    return new ModelVo(StaticKeys.OH_FALSE, "此病人当前不在临床路径内.");
                }
                if (VCS05 == 1 && StringUtils.isBlank(VCS06)) {
                    return new ModelVo(StaticKeys.OH_FALSE, "异常退出路径，需要输入出径原因.");
                }
                //查询病人临床路径
                List<Map<String, Object>> vcnList = doctorordernewDao.queryForList("Doctorordernew.quickinsert_014", map);
                for (Map<String, Object> vcnMap : vcnList) {
                    Long vcs01 = getNewId.nextId();
                    vcnMap.put("vcs01", vcs01);
                }
                map.put("vcnlist", vcnList);
                //插入病人出径记录（VCS1)
                doctorordernewDao.insert("Doctorordernew.quickinsert_015", map);
                //更新临床路径状态（VCN1)
                doctorordernewDao.insert("Doctorordernew.quickinsert_016", map);

            }
            // 预出院信息（更新病人登记表信息VAE1）
            List<Map<String,Object>> PatXmlList =  JsonUtil.getList(lPatXml);
            String abv01 = "";
            String vam38 = "";
            String vam39 = "";

            if(PatXmlList!=null&&PatXmlList.size()>0) {
                for (Map<String, Object> pm1 : PatXmlList) {
                	abv01 = MapUtils.getString(pm1,"ABV01","");
                	vam38 = MapUtils.getString(pm1,"VAM38","");
                	vam39 = MapUtils.getString(pm1,"VAM39","");
                	if(vam39.equals("")){
                		pm1.put("VAM39", null);
                	}
                    doctorordernewDao.update("Doctorordernew.quickinsert_010",pm1);
                }
            }
            //删除门诊病人诊断记录（VAO1)
            doctorordernewDao.delete("Doctorordernew.quickinsert_011",map);
            // 解析病人诊断记录信息
            List<Map<String,Object>> tmpXmlList =  JsonUtil.getList(lXml);
            String param = doctorparameterBo.getSysValue(9999,9999,4);
            Integer liaa01 = (Integer) doctorordernewDao.queryToObject("Doctorordernew.select_iaa01", map);
            map.put("liaa01", liaa01);
            Integer iaj05int = (Integer) doctorordernewDao.queryToObject("Doctorordernew.select_iaj05", map);
            for(Map<String,Object> pm2:tmpXmlList){
            	String vao15 = MapUtils.getString(pm2,"VAO15","");
            	Integer vao25 = MapUtils.getInteger(pm2, "VAO25",0);
            	Integer vao24 = MapUtils.getInteger(pm2, "VAO24",0);
            	Integer bak01a = MapUtils.getInteger(pm2, "BAK01A",0);
            	Integer vao10 = MapUtils.getInteger(pm2, "VAO10",0);
            	String abx01 = MapUtils.getString(pm2,"ABX01","");
            	String iad03 = MapUtils.getString(pm2,"IAD03","");
            	if(vao15.equals("")){
            		return new ModelVo(StaticKeys.OH_FALSE, "出院诊断不能省略.");
            	}
            	if(vao25==0){
            		return new ModelVo(StaticKeys.OH_FALSE, vao15+" 对应诊断分类不能省略.");
            	}
            	if(vao24==0){
            		return new ModelVo(StaticKeys.OH_FALSE, vao15+" 对应入院病情不能省略.");
            	}
            	if(abx01.equals("")){
            		return new ModelVo(StaticKeys.OH_FALSE, vao15+" 对应出院情况不能省略");
            	}
//            	if(param.equals("1")&&bak01a==0){
//            		return new ModelVo(StaticKeys.OH_FALSE, vao15+" 对应疾病ICD编码不能省略.");
//            	}
            	if(liaa01>0 && iaj05int>0){
            		if(vao10==0 && iad03.equals("")){
            			return new ModelVo(StaticKeys.OH_FALSE, "根据医保规定 "+vao15+" 对应保险疾病编码不能省略.");
            		}
            	}
            	if(abv01.equals("5") || abx01.equals("4")){
            		if(abv01.equals("")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人死亡出院时，出院方式应该是死亡.");
            		}
            		if(vam38.equals("")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人死亡出院时，死亡原因不能省略.");
            		}
            		if(vam39.equals("")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人死亡出院时，死亡时间不能省略.");
            		}
            		if(!abx01.equals("4")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人死亡出院，对应出院情况不能没有【死亡】.");
            		}
            	}else{
            		pm2.put("VAE38", "");
            		if(abx01.equals("4")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人非死亡出院，对应出院情况不能有【死亡】.");
            		}
            		if(!vam38.equals("")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人非死亡出院时，死亡原因不能填写值.");
            		}
            		if(!vam39.equals("")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人非死亡出院时，死亡时间不能填写.");
            		}
            		if(abv01.equals("5")){
            			return new ModelVo(StaticKeys.OH_FALSE, "病人非死亡出院时，出院方式不应该是死亡.");
            		}
            	}
                Long VAOID = getNewId.nextId();
                pm2.put("VAOID",VAOID);
                pm2.put("lDateA",nowdate);
                pm2.put("lBCE03",lBCE03);
                pm2.put("liaa01", liaa01);
            }
            
            //插入住院病人诊断记录-西医/中医（VAO2)
            map.put("vaolist",tmpXmlList);
            doctorordernewDao.insert("Doctorordernew.quickinsert_012",map);
        }else if(lMode==3){ //会诊医嘱
            String lVAF23 = MapUtils.getString(map,"lVAF23","");
            String[] lVAF23_arr = StringUtils.split(lVAF23,",");
            List<String> lvafList = Arrays.asList(lVAF23_arr);
            map.put("lvafList",lvafList);
            
            List<Map<String,Object>> tmpBCK = doctorordernewDao.queryForList("Doctorordernew.quickinsert_001",map);
            
            if(tmpBCK!=null&&tmpBCK.size()>0){
                int i = 1;
                for(Map<String,Object> lvafItem:tmpBCK){
                	Map<String,Object> map1 = new HashMap<String,Object>();
                	map1.put("ID",i);
                    Integer BCK01B = MapUtils.getInteger(lvafItem,"bck01");
                    if(BCK01B.intValue()!=0&&tmpBCK!=null){
                        map1.put("BCK01B",BCK01B);
                        if(i==1){
                        	lBCK01B = BCK01B;
                        }
                        String VCL01 = UUID.randomUUID().toString();
                        map1.put("VCL01",VCL01);
                        map1.put("lVAEID",map.get("lVAEID"));
                        map1.put("lVAAID",map.get("lVAAID"));
                        map1.put("lBCK01",lBCK01);
                        map1.put("lBCE01",lBCE01);
                        map1.put("lDate",lDate);
                        tmpvcl.add(map1);
                    }
                    i++;
                }
            }          
        }
        if(!(lMode==4&&VCS05==1)){ //如果不是异常退出路径或是快速插入则插入医嘱记录
            //插入医嘱单记录（CBM2)
        	map.put("BCK01B",lBCK01B);
            Map<String,Object> cbmMap = (Map<String,Object>)doctorordernewDao.queryToObject("Doctorordernew.quickinsert_003",map);
            Long CBM01 = getNewId.nextId();
            cbmMap.put("cbm01",CBM01);
            cbmMap.put("cbm08",CBM01);
            cbmMap.put("bck01c",lBCK01);
            cbmMap.put("bce01",lBCK01);
            cbmMap.put("bce03",lBCE03);
            cbmMap.put("cbm15",lDate);
            map.put("cbmMap",cbmMap);
            doctorordernewDao.insert("Doctorordernew.quickinsert_004",map);
            map.put("lcbm01",CBM01);
            //插入医嘱表(VAF2)
            Long lVAF01 = getNewId.nextId();
            Map<String,Object> vafMap = (Map<String,Object>)doctorordernewDao.queryToObject("Doctorordernew.quickinsert_005",map);
            vafMap.put("vaf01",lVAF01);
            vafMap.put("vaf36",lDate);
            vafMap.put("vaf42",nowdate);
            vafMap.put("vaf74",lDate);
            map.put("vafMap",vafMap);
            map.put("lVAF01",lVAF01);
            doctorordernewDao.insert("Doctorordernew.quickinsert_006",map);
            //插入医嘱状态(VBG2)
            Long lVBG01 = getNewId.nextId();
            map.put("lVBG01",lVBG01);
            doctorordernewDao.insert("Doctorordernew.quickinsert_007",map);
            Map<String,Object> vbgMap = (Map<String,Object>)doctorordernewDao.queryToObject("Doctorordernew.quickinsert_008",map);
            vbgMap.put("vaf01",lVAF01);
            String uuid = UUID.randomUUID().toString();
            vbgMap.put("vbz01",uuid);
            //插入医嘱提醒（VBZ1）
            map.put("vbgMap",vbgMap);
            doctorordernewDao.insert("Doctorordernew.quickinsert_009",map);
            if(lMode==3){
            	if(tmpvcl.size()>0){
            		for(int i=0;i<tmpvcl.size();i++){
            			tmpvcl.get(i).put("lCBM01",CBM01);
            			tmpvcl.get(i).put("lVAF01",lVAF01);
            		}
            	}
            	Map<String,Object> map2 = new HashMap<String,Object>();
                map2.put("tmpvcl",tmpvcl);
                doctorordernewDao.insert("Doctorordernew.quickinsert_013",map2);
            }
            mo = new  ModelVo(StaticKeys.OH_SUCCESS, "执行成功！");
        }
        return mo;
    }

    private List getTmpVAF(JSONObject job, List tmpCBM) {
        int ll = tmpCBM.size();
        Set set = new HashSet<>();
        Integer cbmid = null;
        Map map = null;
        for (int i = 0; i < ll; i++) {
            map = (Map) tmpCBM.get(i);
            cbmid = MapUtils.getInteger(map, "cbmid");
            if (cbmid != null) {
                set.add(cbmid);
            }
        }

        List rs = new ArrayList<>();

        List ls = JsonUtil.parserToList(job.getJSONArray("vaf1"));
        ll = ls.size();
        String lsign = null;

        for (int i = 0; i < ll; i++) {
            map = (Map) ls.get(i);
            lsign = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "lsign");
            if (lsign != null && "0".equals(lsign)) {
                cbmid = MapUtils.getInteger(map, "cbmid");
                if (set.contains(cbmid)) {
                    map.put("bag46", 0d);
                    map.put("bbt07", 0);
                    map.put("bby23", 0d);
                    rs.add(map);
                }
            }
        }
        return rs;
    }

    private List getTmpVAO(JSONObject job) {
        List ls = new ArrayList();
        if (job.containsKey("vao1")) {
            ls = JsonUtil.parserToList(job.getJSONArray("vao1"));
            int ll = ls.size();
            Map map = null;
            for (int i = 0; i < ll; i++) {
                map = (Map) ls.get(i);
                map.put("bak02", "");
            }
        }
        return ls;
    }

    private List getTmpVBQ(JSONObject job) {
        List ls = new ArrayList();
        if (job.containsKey("vbq1")) {
            ls = JsonUtil.parserToList(job.getJSONArray("vbq1"));
            int ll = ls.size();
            Map map = null;
            for (int i = 0; i < ll; i++) {
                map = (Map) ls.get(i);
                map.put("vbqid", 0);
            }
        }
        return ls;
    }
    private List getTmpVAX(JSONObject job) {
        List ls = new ArrayList();
        if (job.containsKey("vax1")) {
            ls = JsonUtil.parserToList(job.getJSONArray("vax1"));
            int ll = ls.size();
            Map map = null;
            for (int i = 0; i < ll; i++) {
                map = (Map) ls.get(i);
                map.put("vaf01", 0);
                map.put("vax01", 0);
                map.put("vat01", 0);
            }
        }
        return ls;
    }
    private List getTmpVAFByBck01b(List tmpVAF, String asign) {
        if ("0".equals(asign)) {
            int ll = tmpVAF.size();
            Map map = null;
            String rcurrent = null;
            for (int i = 0; i < ll; i++) {
                map = (Map) tmpVAF.get(i);
                rcurrent = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "rcurrent");
                if (rcurrent != null && "1".equals(rcurrent)) {
                    map.put("bck01b", 0);
                }
            }
        }
        return tmpVAF;
    }

    private Map getParams(Map map, String ACF01) throws Exception {
        Short isybbr = 0;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Date date = new Date();

        Calendar cl = Calendar.getInstance();
        cl.setTime(date);
        cl.add(Calendar.MONTH, -2);// 减2个月

        Integer type = Integer.valueOf(map.get("type").toString());

        String edate = sdf.format(date);
        String vaj47 = sdf.format(cl.getTime());

        Map param = null;

        // 限制最大销售数量或金额判断
        if ("1".equals(ACF01)) {
            param = doctorordernewDao.getMaxSalePara(map);
            if (Integer.valueOf(param.get("cont").toString()) > 0) {
                isybbr = 1;
            }
        }
        if ("2".equals(ACF01)) {
            if (type.equals(1)) {
                param = doctorordernewDao.getMaxSale21Para(map);
            }
            if (type.equals(2)) {
                param = doctorordernewDao.getMaxSale22Para(map);
            }

            if (Integer.valueOf(param.get("cont").toString()) > 0) {
                isybbr = 1;
            }
        }

        param.put("edate", edate);
        param.put("vaj47", vaj47);
        param.put("isybbr", isybbr);

        return param;
    }
    private int getJudgeSsMz(List tmpVAF) throws Exception {
        return doctorordernewDao.getJudgeSsMz(tmpVAF);
    }
    private String getJudgeMzfs(Map mls) throws Exception {
        return doctorordernewDao.getJudgeMzfs(mls);
    }
    private String getJudgeNoZd(Map mls) throws Exception {
        return doctorordernewDao.getJudgeNoZd(mls);
    }
    private int getBlpBlp0230() throws Exception {
        return doctorordernewDao.getBlpBlp0230();
    }
    private ModelVo getJudgeSs(List tmpVAF, List tmpVAX, Map params, String ACF01) throws Exception {

        if (!"2".equals(ACF01)) {
            return null;
        }
        int tv = tmpVAF.size();

        Map map = null;
        String bda01 = null;
        int cnt = 0;
        for (int i = 0; i < tv; i++) {
            map = (Map) tmpVAF.get(i);
            bda01 = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "bda01");
            if (bda01 != null) {
                if ("S".equals(bda01) || "0".equals(bda01)) {
                    cnt++;
                }
            }
        }
        if (cnt == 0) {
            return null;
        }

        cnt = getJudgeSsMz(tmpVAF);
        if (cnt == 0) {
            return null;
        }

        String zyPara386 = params.get("zypara386").toString();
        Map mls = new HashMap();
        mls.put("tmpVAF", tmpVAF);
        mls.put("tmpVAX", tmpVAX);
        // 没有麻醉方式，请检查.
        if ("1".equals(zyPara386)) {
            String vaf22 = getJudgeMzfs(mls);
            if (vaf22 != null && !"".equals(vaf22)) {
                return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "，没有麻醉方式，请检查.");
            }
            // 没有主刀医师，请检查.
            vaf22 = getJudgeNoZd(mls);
            if (vaf22 != null && !"".equals(vaf22)) {
                return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "，没有主刀医师，请检查.");
            }
        }

        // 没有切口等级，请检查.
        cnt = getBlpBlp0230();
        if (cnt > 0) {
            String vaf22 = doctorordernewDao.getJudgeNoQkdj(mls);
            if (vaf22 != null && !"".equals(vaf22)) {
                return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "，没有切口等级，请检查.");
            }
        }

        return null;
    }
    private ModelVo getJudNoTotal(Map map) throws Exception {
        if (doctorordernewDao.getJudNoTotal(map) > 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "外配处方，需要整张处方药品执行性质都是外配处方，不能有别的执行性质，请检查.");
        }
        return null;
    }
    private ModelVo getJudLydy(Map map) throws Exception {
        if (doctorordernewDao.getJudLydy(map) > 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "离院带药，需要处方药品中本组药品执行性质都是离院带药，本组不能有别的执行性质，请检查.");
        }
        ;
        return null;
    }
    private int getJudgeXcyCt(List tmpVAF) {
        int l = 0;
        int tv = tmpVAF.size();
        Map map = null;
        String bda01 = null;
        for (int i = 0; i < tv; i++) {
            map = (Map) tmpVAF.get(i);
            bda01 = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "bda01");
            if ("1".equals(bda01) || "2".equals(bda01) || "3".equals(bda01)) {
                l++;
            }

        }
        return l;
    }
    @SuppressWarnings("unchecked")
    private ModelVo getJudgeKssYymd(int tcount, Map params, Map cdjMap, String asign) throws Exception {
        String para356_392 = params.get("para356_392").toString();
        cdjMap.put("asign", asign);
        if (tcount > 0 && "1".equals(para356_392)) {
            String vaf22 = doctorordernewDao.getJudgeKssYymd(cdjMap);
            if (vaf22 != null && (!"".equals(vaf22))) {
                return new ModelVo(StaticKeys.OH_FALSE, vaf22 + " 没有用药目的，请填写用药目的.");
            }
        }
        return null;
    }
    private ModelVo getJudgeCfPd(int tcount, Map params, List tmpCBM, List tmpVAO) {
        String mzpara153 = params.get("mzpara153").toString();
        if (tcount > 0 && "1".equals(mzpara153)) {

            Set set = new HashSet<>();
            Map map = null;
            String cbm06 = null;
            int tc = tmpCBM.size();
            // cbm06 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 = 成药,5=卫材, 9=其他
            for (int i = 0; i < tc; i++) {
                map = (Map) tmpCBM.get(i);
                cbm06 = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "cbm06");
                if (cbm06 != null && (!("1".equals(cbm06) || "2".equals(cbm06) || "4".equals(cbm06)))) {
                    return null;
                }
            }

            Integer cbmid = null;
            int tv = tmpVAO.size();
            for (int i = 0; i < tv; i++) {
                map = (Map) tmpVAO.get(i);
                cbmid = MapUtils.getInteger(map, "cbmid");
                if (cbmid != null) {
                    set.add(cbmid);
                }
            }
            if (set.size() == 0) {
                return null;
            }

            for (int i = 0; i < tc; i++) {
                map = (Map) tmpCBM.get(i);
                cbmid = MapUtils.getInteger(map, "cbmid");
                if (set.contains(cbmid)) {
                    cbm06 = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "cbm06");
                    if (cbm06 != null && (!("1".equals(cbm06) || "2".equals(cbm06) || "4".equals(cbm06)))) {
                        return new ModelVo(StaticKeys.OH_FALSE, "药品处方没有诊断，请填写处方诊断.");
                    }
                }
            }
        }

        return null;
    }
    private List getJudgeOnlyXcy(Map cdjMap) throws Exception {
        return doctorordernewDao.getJudgeOnlyXcy(cdjMap);
    }
    private boolean getJEXcf(List tmpVAF) {
        Map map;
        String bag46;
        String bda01;
        int l = tmpVAF.size();

        for (int i = 0; i < l; i++) {
            map = (Map) tmpVAF.get(i);
            bag46 = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "bag46");
            bda01 = com.cnhis.cloudhealth.commons.utils.MapUtils.getString(map, "bda01");
            if (bag46 != null && bda01 != null) {
                if (bag46.compareTo("1") > 0 && ("1".equals(bda01) || "2".equals(bda01))) {
                    return true;
                }
            }
        }

        return false;
    }
    private ModelVo getJudgeExceed(List tmpVAF, Map params, int tcount) throws Exception {
        if (tcount == 0) {
            return null;
        }

        String gpara69 = params.get("gpara69").toString();
        if (gpara69 == null || "0".equals(gpara69)) {
            return null;
        }

        // 西、成药的限额是否大于1
        boolean xcf = getJEXcf(tmpVAF);

        String adate = params.get("edate").toString().substring(0, 7) + "-01";
        params.put("adate", adate);

        Map map = new HashMap<>();
        map.put("tmpVAF", tmpVAF);
        map.put("adate", adate);
        map.putAll(params);
        ;

        String smsg = null;
        // 已超出限售金额
        if ("1".equals(gpara69) && xcf) {
            smsg = doctorordernewDao.getJudgeXsje(map);
        }
        // 超出限售数量
        if ("2".equals(gpara69) && xcf) {
            smsg = doctorordernewDao.getJudgeXssl(map);
        }

        if (smsg != null && (!"".equals(smsg))) {
            return new ModelVo(StaticKeys.OH_FALSE, smsg + "，不能再下达此药品.");
        }

        return null;
    }

    /**
     * 临床药物评价 Clinic_Drug_Judge
     *
     * @param map
     * @return
     * @throws Exception
     */
    public ModelVo clinicDrugJudge(Map map) throws Exception {


        ModelVo mo = null;

        String lxml = map.get("lxml").toString();
        // 将lxml装换为json
        JSONObject job = JSONObject.fromObject(lxml);

        // 获取医嘱单信息
        List TmpCBM = JsonUtil.parserToList(job.getJSONArray("cbm1"));

        if (TmpCBM.size() == 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "医嘱单信息为空");
        }
        // 获取医嘱信息
        List TmpVAF = getTmpVAF(job, TmpCBM);
        if (TmpVAF.size() == 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "医嘱信息为空");
        }

        // 获取诊断信息
        List TmpVAO = getTmpVAO(job);

        // 获取病人诊疗申请单信息
        List TmpVBQ = getTmpVBQ(job);

        // 获取病人手术人员信息
        List TmpVAX = getTmpVAX(job);



        String ACF01 = map.get("ACF01").toString();

        String asign = map.get("asign").toString();

        // 修改执行科室ID
        TmpVAF = getTmpVAFByBck01b(TmpVAF, asign);

        // 获取参数
        Map params = getParams(map, ACF01);

        Map cdjMap = new HashMap<>();
        cdjMap.put("tmpCBM", TmpCBM);
        cdjMap.put("tmpVAF", TmpVAF);
        cdjMap.put("tmpVAO", TmpVAO);
        cdjMap.put("tmpVBQ", TmpVBQ);
        cdjMap.put("tmpVAX", TmpVAX);

        List<HashMap> list = new ArrayList<HashMap>();
        HashMap temp = new HashMap();
        list = doctorordernewDao.getAllBLPList(temp);
        for(HashMap hashMap : list)
        {
            temp.put("txt", "select "+hashMap.get("BLP07"));
            List ls = doctorordernewDao.execProc(temp);
        }



        // 手术医嘱判断
        mo = getJudgeSs(TmpVAF, TmpVAX, params, ACF01);
        if (mo != null) {
            return mo;
        }

        // 外配处方，需要整张处方药品执行性质都是外配处方，不能有别的执行性质，请检查.
        if ("1".equals(asign) && "1".equals(ACF01)) {
            mo = getJudNoTotal(cdjMap);
            if (mo != null) {
                return mo;
            }
        }

        // 离院带药，需要处方药品中本组药品执行性质都是离院带药，本组不能有别的执行性质，请检查.
        if ("1".equals(asign)) {
            mo = getJudLydy(cdjMap);
            if (mo != null) {
                return mo;
            }
        }

        // 西成药品医嘱行数
        int tcount = getJudgeXcyCt(TmpVAF);

        // 抗生素类药品用药目的判断
        mo = getJudgeKssYymd(tcount, params, cdjMap, asign);
        if (mo != null) {
            return mo;
        }

        // 判断处方诊断
        mo = getJudgeCfPd(tcount, params, TmpCBM, TmpVAO);
        if (mo != null) {
            return mo;
        }

        // 只判断西成药品处方
        if (tcount > 0) {
            TmpVAF = getJudgeOnlyXcy(cdjMap);
        }
        cdjMap.put("tmpVAF", TmpVAF);
        // 已超出限售金额;超出限售数量
        // 这里是要统计全院的的药品销售情况

        mo = getJudgeExceed(TmpVAF, params, tcount);
        if(mo==null){
            return new ModelVo(StaticKeys.OH_SUCCESS,"成功！");
        }else{
            return mo;
        }
    }

    public ModelVo selectDrugfeedetail(){return MySqlUtil.packModelVo("Doctorordernew.1754",null,doctorordernewDao);}
    public ModelVo selectPisvip(Map map){return MySqlUtil.packModelVo("Doctorordernew.7307",map,doctorordernewDao);}
    /**
     * 获取医嘱单信息
     *
     * @param job
     * @return
     */
    private List getCviTmpCBM(JSONObject job, Long lbce01, String lbce03)throws Exception{
        List<Map<String,Object>> list = JsonUtil.parserToList(job.getJSONArray("cbm1"));
        if(list!=null&&list.size()>0) {
            for (int i = 0; i < list.size(); i++) {
                Map<String,Object> cbmMap = (Map<String,Object>)list.get(i);
                Map<String,Object> rmap = (Map<String,Object>)doctorordernewDao.queryForExtObject("Doctorordernew.getpatientinfo", cbmMap);
                cbmMap.put("vaa04",MapUtils.getString(rmap,"vaa04",""));
                cbmMap.put("vaa05",MapUtils.getString(rmap,"vaa05",""));
                cbmMap.put("bcq04",MapUtils.getString(rmap,"bcq04",""));
                cbmMap.put("bce01", lbce01);
                cbmMap.put("bce03", lbce03);
                cbmMap.put("cbm01", 0);
                cbmMap.put("vbq01", 0);
            }
        }

        return list;
    }

    private Map<String,Object> getCommonParam(Integer ltype,Map<String,Object> map)throws Exception{
        Map<String, Object> rmap = (Map<String, Object>) doctorordernewDao.queryForExtObject("Doctorordernew.getCviPara", null);
        String pvalue = MapUtils.getString(rmap, "pvalue"); //系统是否开启全责医师医嘱审核制
        String para203 = MapUtils.getString(rmap, "para203"); //开嘱医师与操作员是同一个人时医嘱是否不需要审核
        String gpara50 = MapUtils.getString(rmap, "gpara50");
        String mzpara370 = MapUtils.getString(rmap, "mzpara370");
        map.put("gpara50",gpara50);
        map.put("mzpara370",mzpara370);
        if(ltype>=1&&ltype<=2) {
            //判断操作员部门和人员业务范围是否为麻醉项目
            Integer cntbce = (Integer)doctorordernewDao.queryForExtObject("Doctorordernew.countDrugedBce", map);
            Integer fChange = cntbce==0?1:0;
            //判断操作员职务是否为士级或待聘以上（等于0是大于0不是）
            Integer cntduty = (Integer)doctorordernewDao.queryForExtObject("Doctorordernew.countDuty", map);
            map.put("pvalue", pvalue);
            map.put("fchange", fChange);
            map.put("para203", para203);
            map.put("cntduty", cntduty);
        }else{
            map.put("pvalue", "0");
            map.put("fchange", 0);
            map.put("para203", "0");
        }
        return map;
    }
    //住院更改全责医师信息
    private void processQuanze(Map<String,Object> dataMap,Map<String,Object> pmap) throws Exception{
        Long vaa07 = MapUtils.getLong(dataMap, "vaa07");
        pmap.put("vae01", vaa07);
        Map<String, Object> bceMap = (Map<String, Object>) doctorordernewDao.queryForExtObject("Doctorordernew.gethosdoctor", pmap);
        Long bce01 = MapUtils.getLong(bceMap, "bce01");
        String bce03 = MapUtils.getString(bceMap, "bce03");
        dataMap.put("bce01", bce01);
        dataMap.put("bce03", bce03);
    }
    //处理医嘱单CBM主键和其他信息
    private List processCBM(List<Map<String,Object>> tmpCBM,Map<String,Object> map,Map<String,Object> pmap)throws Exception{
        Integer ltype = MapUtils.getInteger(map,"ltype");
        Long lbce01 = MapUtils.getLong(map,"lbce01");
        Integer fchange = MapUtils.getInteger(map,"fchange");
        Integer cntduty = MapUtils.getInteger(map,"cntduty");
        String pvalue = MapUtils.getString(map, "pvalue");
        List<Long> cbmids = getNewId.nextId(tmpCBM.size());
        //组装医嘱单CBM内容
        for (int i = 0; i < tmpCBM.size(); i++) {
            Integer acf01 = MapUtils.getInteger(tmpCBM.get(i),"acf01");
            Long vbce01 = MapUtils.getLong(tmpCBM.get(i),"bce01");
            tmpCBM.get(i).put("cbm01",cbmids.get(i));
            //更新全责医师  ,当没有授权 允许修改开嘱医师时，且操作员聘任职务>4时，默认住院医师为全责医师
            if(ltype==1&&"1".equals(pvalue)&&fchange==1&&(cntduty!=null&&cntduty>0)&&vbce01==lbce01&&acf01==2){
                processQuanze(tmpCBM.get(i),pmap);
            }
        }
        return tmpCBM;
    }
    //处理检查申请单VBQ主键和其他信息
    private Map<String, List> processVBQ(List<Map<String,Object>> tempVBQ,List<Map<String,Object>> tmpCBM,Map<String,Object> map,Map<String,Object> pmap)throws Exception{
    	Map<String, List> rmap =  new HashMap<String, List>();
        Integer ltype = MapUtils.getInteger(map,"ltype");
        Long lbce01 = MapUtils.getLong(map,"lbce01");
        Integer fchange = MapUtils.getInteger(map,"fchange");
        Integer cntduty = MapUtils.getInteger(map,"cntduty");
        String pvalue = MapUtils.getString(map, "pvalue");
        String ldate = MapUtils.getString(map, "ldate");
        //生成医嘱单VBQ主键
        if(tempVBQ!=null&&tempVBQ.size()>0) {
            List<Long> vbqids = getNewId.nextId(tempVBQ.size());
            ldate = ldate.substring(0, 4);
            for (int i = 0; i < tempVBQ.size(); i++) {
                Map<String, Object> vbqMap = (Map<String, Object>) tempVBQ.get(i);
                Integer acf01 = MapUtils.getInteger(tempVBQ.get(i), "acf01");
                Long vbce01 = MapUtils.getLong(tempVBQ.get(i), "bce01");
                String vbq01 = MapUtils.getString(tempVBQ.get(i), "vbq01");
                tempVBQ.get(i).put("vbq01", vbqids.get(i));
                for (int j = 0; j < tmpCBM.size(); j++) {
                    Map<String, Object> maptc = (Map<String, Object>) tmpCBM.get(j);
                    String cbmid = MapUtils.getString(tmpCBM.get(j), "cbmid");
                    if (vbq01.equals(cbmid)) {
                    	tmpCBM.get(j).put("vbq01", vbqids.get(i));
                    }
                }

                tempVBQ.get(i).put("vbq15", "JC" + ldate + String.format("%010d", vbqids.get(i)));
                //更新全责医师  ,当没有授权 允许修改开嘱医师时，且操作员聘任职务>4时，默认住院医师为全责医师
                if (ltype == 1&& "1".equals(pvalue)&& fchange == 1&& (cntduty != null && cntduty > 0)&& vbce01 == lbce01 && acf01 == 2) {
                    processQuanze(tempVBQ.get(i),pmap);
                }
            }
        }
        rmap.put("tmpVBQ", tempVBQ);
        rmap.put("tmpCBM", tmpCBM);
        return rmap;
    }
    /**
     * 获取医嘱内容信息
     *
     * @param job
     * @return
     */
    private Map<String, List> getCviTmpVAF(JSONObject job, List<Map<String,Object>> tmpCBM,List<Map<String,Object>> tempVBQ,Map<String,Object> map)throws Exception{
    	Map<String, List> Rmap = new HashMap<String, List>();
        Integer ltype = MapUtils.getInteger(map,"ltype");
        getCommonParam(ltype,map);
        Long lbce01 = MapUtils.getLong(map,"lbce01");
        Integer fchange = MapUtils.getInteger(map,"fchange");
        Integer cntduty = MapUtils.getInteger(map,"cntduty");
        String pvalue = MapUtils.getString(map, "pvalue");
        String gpara50 = MapUtils.getString(map, "gpara50");
        List<Map<String,Object>> list = JsonUtil.parserToList(job.getJSONArray("vaf1"));
        Map<String,Object> pmap = new HashMap<String,Object>();

        //处理医嘱单CBM主键和其他信息
        tmpCBM = processCBM(tmpCBM,map,pmap);
        //处理检查申请单VBQ主键和其他信息
        Map<String, List> xmap = processVBQ(tempVBQ,tmpCBM,map,pmap);
        tmpCBM = xmap.get("tmpCBM");
        tempVBQ = xmap.get("tmpVBQ");
        //生成医嘱单VAF主键
        List<Long> vafids = getNewId.nextId(list.size());
        Iterator<Map<String,Object>> it = list.iterator();
        int i =0;
        Map<Integer,Long> idMap = new HashMap<Integer,Long>();
        while(it.hasNext()){
            Map<String,Object> vafMap = it.next();
            Long vbce01a = MapUtils.getLong(vafMap,"bce01a");   //开嘱医师ID
            Integer vaf04 = MapUtils.getInteger(vafMap,"vaf04");    //1-门诊 2-住院
            String bda01 = MapUtils.getString(vafMap,"bda01");  //诊疗项目类型
            Integer vaf32 = MapUtils.getInteger(vafMap,"vaf32"); //0-正常 1-给药途径
            Integer bck01b = MapUtils.getInteger(vafMap,"bck01b",0);  //执行科室ID
            Integer bck01d = MapUtils.getInteger(vafMap,"bck01d",0);  //给药科室ID
            Integer bby01 = MapUtils.getInteger(vafMap,"bby01",0);  //收费项目ID
            Integer vaf11 = MapUtils.getInteger(vafMap,"vaf11");    //1-长嘱 2-临嘱
            String vaf23 = MapUtils.getString(vafMap,"vaf23","");    //医师嘱托
            Integer vaf27 = MapUtils.getInteger(vafMap,"vaf27",0);  //频率次数
            Integer rownr = MapUtils.getInteger(vafMap,"rownr");    //序号
            String vaf60 = MapUtils.getString(vafMap,"vaf60","0");  //滴速
            Integer vaf17 = MapUtils.getInteger(vafMap,"vaf17",0);  //天数
            Integer vaf59 = MapUtils.getInteger(vafMap,"vaf59",1);  //组号
            vafMap.put("vaf01",vafids.get(i));
            if (rownr == 0) {
                Long vaf01a = vafids.get(i);
                idMap.put(vaf59,vaf01a);
                vafMap.put("vaf01a",0l);
            }
            //如果医嘱内容项目为西药（1）/中成药（2）/中草药（3）,更新药品用药标识
            if(("1".equals(bda01)||"2".equals(bda01)||"3".equals(bda01))) {
                Map<String, Object> tempMap = new HashMap<String, Object>();
                tempMap.put("bby01", bby01);
                Map<String, Object> drugMap = (Map<String, Object>) doctorordernewDao.queryForExtObject("Doctorordernew.getdruginfo", tempMap);
                Integer vaf75 = MapUtils.getInteger(drugMap, "vaf75",0);
                vafMap.put("vaf75", vaf75);
            }
            //如果医嘱内容项目为治疗（T）和方剂（8），执行性质为给药途径，且执行科室不为空但给药科室为空，则更改给药科室为执行科室
            if(("8".equals(bda01)||"T".equals(bda01))&&vaf32==1&&bck01b>0&&bck01d==0){
                vafMap.put("bck01d",bck01b);
            }
            //如果医嘱内容项目为西药（1）/中成药（2）/中草药（3），且执行科室不为空但给药科室为空，则更改给药科室为执行科室
            if(("1".equals(bda01)||"2".equals(bda01)||"3".equals(bda01))&&bck01b>0&&bck01d==0){
                vafMap.put("bck01d",bck01b);
            }
            //更改医嘱紧急状态（如果为长嘱则更改紧急状态为正常）
            if(vaf11==1){vafMap.put("vaf35",0);}
            //更改频率次数（如果频率次数小于1则默认为1）
            if(vaf27<1){vafMap.put("vaf27",1);}
            //更改滴速（如果项目为西/成药或为治疗项目而且滴速为0则设置滴速为空）
            if(("1".equals(bda01)||"2".equals(bda01))||(vaf32==1 &&"T".equals(bda01))){
                if("0".equals(vaf60)){
                    vafMap.put("vaf60","");
                }
            }
            //如果医嘱内容项目为西药（1）/中成药（2）或者为治疗项目且天数为空或0则默认天数为1
            if(("1".equals(bda01)||"2".equals(bda01)||(vaf32==1 &&"T".equals(bda01)))&&vaf17==0){
                vafMap.put("vaf17",1);
            }
            //如果医嘱内容项目为西药（1）/中成药（2），且医嘱嘱托为皮试
            if(("1".equals(bda01)||"2".equals(bda01))&&vaf23.equals(gpara50)){
                vafMap.put("vaf25","?");
            }else{
                vafMap.put("vaf25","");
            }
            vafMap.put("vaf28",MapUtils.getInteger(vafMap,"vaf28",0)); //频率间隔默认值
            vafMap.put("vaf29",MapUtils.getString(vafMap,"vaf29","")); //间隔单位默认值
            vafMap.put("audit_type",0);
            vafMap.put("crypt",0);
            //更新全责医师  ,当没有授权 允许修改开嘱医师时，且操作员聘任职务>4时，默认住院医师为全责医师
            if(ltype==1&&"1".equals(pvalue)&&fchange==1&&(cntduty!=null&&cntduty>0)&&vbce01a==lbce01&&vaf04==2){
                Long vaf06 = MapUtils.getLong(vafMap,"vaf06");
                pmap.put("vae01",vaf06);
                Map<String,Object> bceMap = (Map<String,Object>)doctorordernewDao.queryForExtObject("Doctorordernew.gethosdoctor", pmap);
                Long bce01 = MapUtils.getLong(bceMap,"bce01");
                String bce02 = MapUtils.getString(bceMap,"bce02");
                String bce03 = MapUtils.getString(bceMap,"bce03");
                vafMap.put("bce01a",bce01);
                vafMap.put("bce02a",bce02);
                vafMap.put("bce03a",bce03);
            }
            String lsign = MapUtils.getString(vafMap,"lsign");
            if (lsign != null && "0".equals(lsign)) {
                String cbmid = MapUtils.getString(vafMap, "cbmid");
                for (int j = 0; j < tmpCBM.size(); j++) {
                    Map<String,Object> maptc = (Map<String,Object>) tmpCBM.get(j);
                    String cbmidtc = MapUtils.getString(maptc,"cbmid");
                    if (cbmid.equals(cbmidtc)){
                        vafMap.put("cbm01", maptc.get("cbm01"));
                    }
                }
            }
            i++;
        }
        //医嘱相关id赋值
        Iterator<Map<String,Object>> it2 = list.iterator();
        while(it2.hasNext()) {
            Map<String,Object> vafMap = it2.next();
            Integer rownr = MapUtils.getInteger(vafMap,"rownr");    //序号
            Integer vaf59 = MapUtils.getInteger(vafMap,"vaf59");    //组号
            if (rownr > 0&&!idMap.isEmpty()) {
                vafMap.put("vaf01a",idMap.get(vaf59));
            }
        }
        Rmap.put("TmpVAF", list);
        Rmap.put("tmpCBM", tmpCBM);
        Rmap.put("tempVBQ", tempVBQ);
        return Rmap;
    }


    //获取诊疗单信息
    private List getCviTmpVAO(JSONObject job,List<Map<String,Object>> tmpCBM) {
        if (!job.containsKey("vao1")) {
            return new ArrayList();
        }
        List list = JsonUtil.parserToList(job.getJSONArray("vao1"));
        if(list!=null&&list.size()>0){
            List<Long> vaoids = getNewId.nextId(list.size());
            for (int i = 0; i < list.size(); i++) {
                Map<String,Object> vaoMap = (Map<String,Object>) list.get(i);
                vaoMap.put("vao01",vaoids.get(i));
                String cbmidtc = MapUtils.getString(vaoMap,"cbmid");
                for (int j = 0; j < tmpCBM.size(); j++) {
                    Map<String,Object> maptc = (Map<String,Object>) tmpCBM.get(j);
                    String cbmid = MapUtils.getString(maptc,"cbmid");
                    if (cbmidtc.equals(cbmid)) {
                        vaoMap.put("cbm01",maptc.get("cbm01"));
                        vaoMap.put("acf01",maptc.get("acf01"));
                        vaoMap.put("vaa01",maptc.get("vaa01"));
                        vaoMap.put("vao07",0);
                        vaoMap.put("vao10",0);
                        vaoMap.put("vao18",0);
                        vaoMap.put("vao22",1);
                    }
                }
            }
        }

        return list;
    }

    //获取病人诊疗申请单
    private List getCviTmpVBQ(JSONObject job) {
        if (!job.containsKey("vbq1")) {
            return new ArrayList<Map<String,Object>>();
        }
        List<Map<String,Object>> list = JsonUtil.parserToList(job.getJSONArray("vbq1"));
        for (int i = 0; i < list.size(); i++) {
            Map<String,Object> map = (Map<String,Object>) list.get(i);
            map.put("vbqid", 0);
        }
        return list;
    }
    //获取手术人员信息
    private List getCviTmpVAX(JSONObject job) {
        if (!job.containsKey("vax1")) {
            return new ArrayList();
        }
        List ls = JsonUtil.parserToList(job.getJSONArray("vax1"));
        int l = ls.size();
        Map map = null;
        for (int i = 0; i < l; i++) {
            map = (Map) ls.get(i);
            map.put("vaf01", 0);
            map.put("vax01", 0);
            map.put("vat01", 0);
        }
        return ls;
    }

    //更新病人手术人员信息，获取病人医嘱附件
    private List getCviTmpVBF(List<Map<String,Object>> tmpVAX, List<Map<String,Object>> tmpVAF) {
        int tvx = tmpVAX.size();
        if (tvx == 0) {
            return tmpVAX;
        }

        int tvf = tmpVAF.size();
        // 更新病人手术人员信息ID
        List<Long> ls = getNewId.nextId(tvx);
        for (int i = 0; i < tvx; i++) {
            Map<String,Object> mapx = (Map<String,Object>) tmpVAX.get(i);
            mapx.put("vax01", ls.get(i));
            String cbmid = MapUtils.getString(mapx,"cbmid");
            String vaf59 = MapUtils.getString(mapx,"vaf59");
            String rownr = MapUtils.getString(mapx,"rownr");
            for (int j = 0; j < tvf; j++) {
                Map<String,Object> mapf = (Map) tmpVAF.get(j);
                String cbmidr = MapUtils.getString(mapf,"cbmid");
                String vaf59r = MapUtils.getString(mapf,"vaf59");
                String rownrr = MapUtils.getString(mapf,"rownr");
                if (cbmid.equals(cbmidr) && vaf59.equals(vaf59r) && rownr.equals(rownrr)) {
                    mapx.put("vaf01", mapf.get("vaf01"));
                    break;
                }

            }
        }

        //获取病人医嘱附件信息
        List<Map<String,Object>> tmpVBF = new ArrayList<Map<String,Object>>();
        for (int i = 0; i < tvx; i++) {
            Map<String,Object> mapx = (Map<String,Object>)tmpVAX.get(i);
            String ace01 = MapUtils.getString(mapx,"ace01");
            if ( "--".equals(ace01)) {
                Map<String,Object> map = new HashMap<String,Object>();
                map.put("vaf01", mapx.get("vaf01"));
                map.put("bce02", mapx.get("bce02"));
                map.put("bce03", mapx.get("bce03"));
                tmpVBF.add(map);
            }
        }

        int tvbf = tmpVBF.size();
        if (tvbf == 0) {
            return tmpVBF;
        }
        //更新病人医嘱附件ID
        ls = getNewId.nextId(tvbf);
        for (int i = 0; i < tvbf; i++) {
            Map<String,Object> map = (Map<String,Object>)tmpVBF.get(i);
            map.put("vbf01", ls.get(i));
        }
         return tmpVBF;
    }
    /**
     * 根据医嘱单id删除医嘱
     * Clinic_Advice_CBM01_Del
     *
     * @param map
     * @return
     */
    public ModelVo delclinicAdviceCBM01(Map map)
    {
    	/*
    	 *新增医嘱修改状态信息
		 *根据医嘱ID删除：1、诊断结果；2、诊疗信息；3、医嘱单；4、医嘱记录
		 */

        ModelVo mv = new ModelVo();
        try
        {
            List<Long> ls = getNewId.nextId((int)(Math.random() * 100));
            map.put("VBG01", ls.get(0).intValue());
//		    map.put("txt", "select wjProc()");
            doctorordernewDao.addVBG1(map);
            doctorordernewDao.delVAO1ByCBM01(map);
            doctorordernewDao.delVBQ1ByCBM01(map);

            doctorordernewDao.delCBM1ByCBM01(map);
            doctorordernewDao.delVAF1ByCBM01(map);

            mv.setResultMsg(StaticKeys.OH_SUCCESS);
            return mv;
        }
        catch (Exception e)
        {
            mv.setResultMsg(StaticKeys.OH_FALSE);
            return mv;
        }

    }
    private void insertCviCBM(Map<String,Object> map) throws Exception {
        doctorordernewDao.insert("Doctorordernew.insertCviCBM", map);
    }

    //插入病人申请单信息
    private void insertCviVbq(Map<String,Object> map) throws Exception {
        if(map.get("tmpVBQ")!=null){
            List<Map<String,Object>> tmpVBQ = (List<Map<String,Object>>)map.get("tmpVBQ");
            if(tmpVBQ.size()>0) {
                doctorordernewDao.insert("Doctorordernew.insertCviVbq", map);
            }
        }
    }

    //插入医嘱内容
    private void insertCviVaf(Map<String,Object> map) throws Exception {
        doctorordernewDao.insert("Doctorordernew.insertCviVaf", map);
    }
    //插入诊断记录
    private void insertCviVao(Map map) throws Exception {
        if(map.get("tmpVAO")!=null){
            List<Map<String,Object>> tmpVAO = (List<Map<String,Object>>)map.get("tmpVAO");
            if(tmpVAO.size()>0) {
                doctorordernewDao.insert("Doctorordernew.insertCviVao", map);
            }
        }
    }

    //插入医嘱状态
    private void insertCviVbg(Map<String,Object> map) throws Exception {
        if(map.get("tmpVAF")!=null){
            List<Map<String,Object>> tmpVAF = (List<Map<String,Object>>)map.get("tmpVAF");
            if(tmpVAF.size()>0) {
                List<Long> vbgids = getNewId.nextId(tmpVAF.size());
                Iterator<Map<String,Object>> it = tmpVAF.iterator();
                int i = 0;
                while(it.hasNext()) {
                    Map<String, Object> vafMap = it.next();
                    vafMap.put("vbgid", vbgids.get(i));
                    i++;
                }
                doctorordernewDao.insert("Doctorordernew.insertCviVbg", map);
            }
        }
    }

    //更新私人诊疗项目
    private void updateCviBdj(Map<String,Object> map) throws Exception {
        Integer lacf01 = MapUtils.getInteger(map,"lacf01");
        Integer lmode = MapUtils.getInteger(map,"lmode");
        String lbce01 = MapUtils.getString(map,"lbce01");
        if(!(lacf01==1&&lmode==2)) {
            List<Map<String, Object>> bdjList = doctorordernewDao.queryForList("Doctorordernew.getCviKbmBDJ", map);
            List<Map<String, Object>> vafList = (List<Map<String, Object>>) map.get("tmpVAF");
            Iterator<Map<String, Object>> it1 = vafList.iterator();
            
            int i = 0, j = 0;
            List<Map<String,Object>> resultMap = new ArrayList<Map<String,Object>>();
            while (it1.hasNext()) {
                Map<String, Object> vafMap = it1.next();
                String bda01 = MapUtils.getString(vafMap, "bda01");
                String bby01 = MapUtils.getString(vafMap, "bby01");
                String bbx01 = MapUtils.getString(vafMap, "bbx01");
                Iterator<Map<String, Object>> it2 = bdjList.iterator();
                while (it2.hasNext()) {
                    Map<String,Object> tmpMap = new HashMap<String,Object>();
                    Map<String, Object> bdjMap = it2.next();
                    String tbbx01 = MapUtils.getString(bdjMap, "bbx01","0");
                    String bce01 = MapUtils.getString(bdjMap, "bce01","0");
                    Long vaf01 = MapUtils.getLong(bdjMap,"vaf01",0l);
                    if ((((bda01.charAt(0) >= '1' && bda01.charAt(0) <= '4') || "M".equals(bda01)) && tbbx01.equals(bby01))
                            || (bda01.charAt(0) >= 'A' && !"M".equals(bda01) && tbbx01.equals(bbx01))) {
                        if (!"0".equals(bda01) && !"8".equals(bda01) && bce01.equals(lbce01)) {
                            tmpMap.put("bda01",bda01);
                            if((bda01.charAt(0) >= '1' && bda01.charAt(0) <= '4') || "M".equals(bda01)) {
                                tmpMap.put("bbx01",bby01);
                            }else if(bda01.charAt(0) >= 'A' && !"M".equals(bda01) ){
                                tmpMap.put("bbx01",bbx01);
                            }
                            if((("E".equals(bda01)||"S".equals(bda01)||"A".equals(bda01))&&vaf01.longValue()>0)){
                                tmpMap.put("vaf01",0l);
                            }else{
                                tmpMap.put("vaf01",vaf01);
                            }
                        }
                    }
                    if(!tmpMap.isEmpty()) {
                        resultMap.add(tmpMap);
                    }
                    j++;
                }
                i++;
            }
            Map<String,String> lMap = new HashMap<String,String>();
            if(resultMap.size()>0) {
                Iterator<Map<String, Object>> it3 = resultMap.iterator();
                while(it3.hasNext()){
                    Map<String,Object> rmap = it3.next();
                    String bda01 = MapUtils.getString(rmap,"bda01");
                    String bbx01 = MapUtils.getString(rmap,"bbx01");
                    Long vaf01 = MapUtils.getLong(rmap,"vaf01");
                    String key = bda01+"-"+bbx01;
                    String value = vaf01+"-"+1;
                    if(lMap.get(key)!=null){
                        String lvalue = lMap.get(key);
                        String larr[] = lvalue.split("-");
                        String lvaf01 = larr[0];
                        String fnum = larr[1];
                        Long max = Long.valueOf(lvaf01);
                        Integer fn = Integer.valueOf(fnum);
                        fn +=1;
                        if(vaf01.longValue()>max.longValue()){
                            lMap.put(key,vaf01+"-"+fn);
                        }else{
                            lMap.put(key,max+"-"+fn);
                        }
                    }else{
                        lMap.put(key,value);
                    }

                }
            }

            if(lMap.size()>0){
                List<Map<String,Object>> plist = new ArrayList<Map<String,Object>>();

                for (Map.Entry<String, String> entry : lMap.entrySet()) {
                    Map<String,Object> tmap = new HashMap<String,Object>();
                    String key = entry.getKey();
                    String value = entry.getValue();
                    String bda01 = key.split("-")[0];
                    String bbx01 = key.split("-")[1];
                    String vaf01 = value.split("-")[0];
                    String fnum = value.split("-")[1];
                    tmap.put("bda01",bda01);
                    tmap.put("bbx01",Integer.valueOf(bbx01));
                    tmap.put("vaf01",Long.valueOf(vaf01));
                    tmap.put("vaf01",Long.valueOf(vaf01));
                    tmap.put("fnum",Integer.valueOf(fnum));
                    tmap.put("lbce01",lbce01);
                    plist.add(tmap);
                }
                if(plist.size()>0){
                    Iterator<Map<String,Object>> it3 = plist.iterator();
                    while(it3.hasNext()){
                        Map<String,Object> tmap =  it3.next();
                        doctorordernewDao.update("Doctorordernew.updateCviBdj",tmap);
                    }
                }
            }
        }
    }
    private boolean existsBdj(Map<String,Object> map,List<Map<String,Object>> bdjList,String bda01,String bbx01,String bby01,String lbce01)throws Exception{
        Iterator<Map<String, Object>> it = bdjList.iterator();
        boolean flag = false;
        while (it.hasNext()) {

            Map<String, Object> bdjMap = it.next();
            String tbbx01 = MapUtils.getString(bdjMap, "bbx01","0");
            String bce01 = MapUtils.getString(bdjMap, "bce01","0");
            if ((((bda01.charAt(0) >= '1' && bda01.charAt(0) <= '4') || "M".equals(bda01)) && tbbx01.equals(bby01))
                    || (bda01.charAt(0) >= 'A' && !"M".equals(bda01) && tbbx01.equals(bbx01)) && bce01.equals(lbce01)) {
                flag = true;
            }

        }
        return flag;
    }

    //插入私人诊疗项目
    private void insertCviBdj(Map<String,Object> map) throws Exception {
        Integer lacf01 = MapUtils.getInteger(map, "lacf01");
        Integer lmode = MapUtils.getInteger(map, "lmode");
        String lbce01 = MapUtils.getString(map, "lbce01");
        if (!(lacf01 == 1 && lmode == 2)) {
            List<Map<String, Object>> bdjList = doctorordernewDao.queryForList("Doctorordernew.getCviKbmBDJ", map);
            List<Map<String, Object>> vafList = (List<Map<String, Object>>) map.get("tmpVAF");
            Iterator<Map<String, Object>> it1 = vafList.iterator();
            int i = 0, j = 0;
            List<Map<String, Object>> resultMap = new ArrayList<Map<String, Object>>();
            while(it1.hasNext()){
                Map<String, Object> vafMap = it1.next();
                String bda01 = MapUtils.getString(vafMap, "bda01");
                String bby01 = MapUtils.getString(vafMap, "bby01");
                String bbx01 = MapUtils.getString(vafMap, "bbx01");
                Long vaf01 = MapUtils.getLong(vafMap, "vaf01",0l);
                Long vaf01a = MapUtils.getLong(vafMap, "vaf01a",0l);
                if(!"0".equals(bda01) && !"8".equals(bda01)){
                    Map<String, Object> tmpMap = new HashMap<String, Object>();
                    boolean flag = existsBdj(map,bdjList,bda01,bbx01,bby01,lbce01);
                    if (!flag) {
                        tmpMap.put("bda01", bda01);
                        if((("E".equals(bda01)||"S".equals(bda01)||"A".equals(bda01))&&vaf01a>0)||"3".equals(bda01)){
                            vaf01 = 0l;
                        }
                        tmpMap.put("vaf01", vaf01);
                        if ((bda01.charAt(0) >= '1' && bda01.charAt(0) <= '4') || "M".equals(bda01)) {
                            tmpMap.put("bbx01", bby01);
                        } else if (bda01.charAt(0) >= 'A' && !"M".equals(bda01)) {
                            tmpMap.put("bbx01", bbx01);
                        }
                    }
                    if (!tmpMap.isEmpty()) {
                        resultMap.add(tmpMap);
                    }
                }
            }
            Map<String, String> lMap = new HashMap<String, String>();
            if (resultMap.size() > 0) {
                Iterator<Map<String, Object>> it2 = resultMap.iterator();
                while (it2.hasNext()) {
                    Map<String, Object> rmap = it2.next();
                    String bda01 = MapUtils.getString(rmap, "bda01");
                    String bbx01 = MapUtils.getString(rmap, "bbx01");
                    Long vaf01 = MapUtils.getLong(rmap, "vaf01");
                    String key = bda01 + "-" + bbx01;
                    String value = vaf01 + "-" + 1;
                    if (lMap.get(key) != null) {
                        String lvalue = lMap.get(key);
                        String larr[] = StringUtils.split(lvalue,"-");
                        String lvaf01 = larr[0];
                        String fnum = larr[1];
                        Long max = Long.valueOf(lvaf01);
                        Integer fn = Integer.valueOf(fnum);
                        fn += 1;
                        if (vaf01.longValue() > max.longValue()) {
                            lMap.put(key, vaf01 + "-" + fn);
                        } else {
                            lMap.put(key, max + "-" + fn);
                        }
                    } else {
                        lMap.put(key, value);
                    }

                }
            }

            if (lMap.size() > 0) {
                List<Map<String, Object>> plist = new ArrayList<Map<String, Object>>();
                for (Map.Entry<String, String> entry : lMap.entrySet()) {
                    Map<String, Object> tmap = new HashMap<String, Object>();
                    String key = entry.getKey();
                    String value = entry.getValue();
                    String bda01 = key.split("-")[0];
                    String bbx01 = key.split("-")[1];
                    String vaf01 = value.split("-")[0];
                    String fnum = value.split("-")[1];
                    tmap.put("bdj01", getNewId.nextId());
                    tmap.put("bda01", bda01);
                    tmap.put("bbx01", Integer.valueOf(bbx01));
                    tmap.put("vaf01", Long.valueOf(vaf01));
                    tmap.put("vaf01", Long.valueOf(vaf01));
                    tmap.put("bdj04", Integer.valueOf(fnum));
                    tmap.put("lbce01", lbce01);
                    tmap.put("bck01", 0);
                    plist.add(tmap);
                }
                if (plist.size() > 0) {
                    map.put("tmpBDJ", plist);
                    doctorordernewDao.insert("Doctorordernew.insertCviBdj", map);
                }
            }
        }
    }


    //插入手术人员信息和医嘱附件
    private void insertCviVax(Map<String,Object> map) throws Exception {
        List<Map<String,Object>> tmpVAX = (List<Map<String,Object>>)map.get("tmpVAX");
        List<Map<String,Object>> tmpVBF = (List<Map<String,Object>>)map.get("tmpVBF");
        List<Map<String, Object>> vaxList = new ArrayList<Map<String, Object>>();
        if(tmpVAX!=null&&tmpVAX.size()>0) {
            int tvx = tmpVAX.size();
            for (int i = 0; i < tvx; i++) {
                Map<String, Object> vaxMap = (Map<String, Object>) tmpVAX.get(i);
                String ace01 = MapUtils.getString(vaxMap, "ace01");
                Long vaf01 = MapUtils.getLong(vaxMap, "vaf01");
                if (StringUtils.isNotBlank(ace01) && (!"--".equals(ace01)) && (vaf01 > 0)) {
                    vaxList.add(vaxMap);
                }
            }
        }
        if (vaxList.size() > 0) {
            map.put("tmpVAX", vaxList);
            doctorordernewDao.insert("Doctorordernew.insertCviVax", map);
        }
        if(tmpVBF!=null&&tmpVBF.size()>0) {
            int tvf = tmpVBF.size();
            if (tvf > 0) {
                doctorordernewDao.insert("Doctorordernew.insertCviVbf", map);
            }
        }
    }
    private void updateCviVcj1(Map<String,Object> map) throws Exception {
        List<Map<String,Object>> tmpCBM = (List<Map<String,Object>>)map.get("tmpCBM");
        //医嘱插入目前只针对一个病人，所以取一个病人的挂号ID即可
        Long vaa07 = 0l;
        int tc = tmpCBM.size();
        for (int i = 0; i < tc; i++) {
            Map cbmMap = (Map) tmpCBM.get(i);
            String vaa07s = MapUtils.getString(cbmMap, "vaa07");
            if (StringUtils.isNotBlank(vaa07s)) {
                vaa07 = Long.valueOf(vaa07s);
                break;
            }
        }

        //查看病人挂号附表中是否有该病人
        map = new HashMap();
        map.put("vaa07",vaa07);
        map.put("ldate",MapUtils.getString(map,"ldate"));
        Integer ct = (Integer)doctorordernewDao.queryForExtObject("Doctorordernew.getCviHasVaa07", map);
        if(ct>0){
            doctorordernewDao.update("Doctorordernew.updateCviVcj1", map);
        }
        else{
            doctorordernewDao.insert("Doctorordernew.insertCviVcj1", map);
        }

        String mzpara370 = MapUtils.getString(map,"mzpara370");
        if(mzpara370!=null&&"1".equals(mzpara370)){
            doctorordernewDao.update("Doctorordernew.updateCviFromMzpara370", map);
        }
    }

    //校验医嘱内容信息
    private ModelVo validateTmpVAF(List<Map<String,Object>> tmpVAF,Map<String,Object> map)throws Exception{
        Integer lacf01 = MapUtils.getInteger(map,"lacf01"); //1-门诊 2-住院
        Integer ltype = MapUtils.getInteger(map,"ltype");
        Integer fchange = MapUtils.getInteger(map,"fchange");
        String pvalue = MapUtils.getString(map, "pvalue");
        String para203 = MapUtils.getString(map,"para203");
        String lbce01 = MapUtils.getString(map,"lbce01");
        String ldate = MapUtils.getString(map,"ldate");
        Map<String,Integer> rmap = new HashMap<String,Integer>();
        for (int i = 0; i < tmpVAF.size(); i++) {
            Map<String,Object> vafMap = (Map) tmpVAF.get(i);
            String cbmid = MapUtils.getString(vafMap,"cbmid");
            String vaf59 = MapUtils.getString(vafMap,"vaf59");  //组号
            String vaf36 = MapUtils.getString(vafMap,"vaf36"); //获取医嘱开始时间
            String vaf37 = MapUtils.getString(vafMap,"vaf37"); //获取长嘱结束时间
            String bda01 = MapUtils.getString(vafMap,"bda01");  //诊疗类型
            String vaf26 = MapUtils.getString(vafMap,"bda01");  //执行频次
            Integer vaf10 = MapUtils.getInteger(vafMap,"vaf10");  //执行状态
            Integer bck01b = MapUtils.getInteger(vafMap,"bck01b",0);  //执行科室
            Integer bck01d = MapUtils.getInteger(vafMap,"bck01d",0);  //给药科室
            Integer bck01c = MapUtils.getInteger(vafMap,"bck01c",0);   //开嘱科室
            Integer vaf32 = MapUtils.getInteger(vafMap,"vaf32",0);  //0-正常 1-给药途径
            Integer vaf11 = MapUtils.getInteger(vafMap,"vaf11");    //1-长嘱 2-临嘱
            String vaf22 = MapUtils.getString(vafMap,"vaf22");  //医嘱内容
            String bce01a = MapUtils.getString(vafMap,"bce01a","");  //医嘱内容

            //判断医嘱内容开始时间不能为空
            if (StringUtils.isBlank(vaf36)) {
                return new ModelVo(StaticKeys.OH_FALSE, "医嘱开始时间不能省略！");
            }
            //如果是门诊医嘱，则判断医嘱内容用药频次不能为空
            if(lacf01==1&&("1".equals(bda01)||"2".equals(bda01))&&StringUtils.isBlank(vaf26)){
                return new ModelVo(StaticKeys.OH_FALSE, "医嘱没有用药频次，请修改！");
            }
            //如果是住院医嘱，则判断修改执行状态
            if(lacf01==2&&vaf10>11){
                vafMap.put("audit_type",vaf10-11);
                vafMap.put("vaf10",11);
            }
            //判断执行科室
            if(bck01b==0){
                return new ModelVo(StaticKeys.OH_FALSE, "医嘱执行科室不正确，请检查修改！");
            }
            //判断给药途径对应附加执行科室
            if(bck01d==0&&("8".equals(bda01)||"T".equals(bda01))&&vaf32==1){
                return new ModelVo(StaticKeys.OH_FALSE, "治疗或方剂医嘱执行科室不正确，请检查修改！");
            }
            //判断西成药和种草要附加执行科室
            if(bck01d==0&&("1".equals(bda01)||"2".equals(bda01)||"3".equals(bda01))){
                return new ModelVo(StaticKeys.OH_FALSE, "西/中草药医嘱执行科室不正确，请检查修改！");
            }

            //判断开嘱科室
            if(bck01c==0){
                return new ModelVo(StaticKeys.OH_FALSE, "医嘱开嘱科室不正确，请检查修改！");
            }
            //若是长嘱，则判断结束时间是否正确,若是临嘱则默认给值
            if(vaf11==1){
                if(StringUtils.isBlank(vaf37)){
                    return new ModelVo(StaticKeys.OH_FALSE, "长嘱结束时间不能为空！");
                }
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                Date begin = org.apache.commons.lang.time.DateUtils.parseDate(vaf36,new String[]{"yyyy-MM-dd hh:mm:ss"});
                Date end = org.apache.commons.lang.time.DateUtils.parseDate(vaf37,new String[]{"yyyy-MM-dd hh:mm:ss"});
                Date cdate = df.parse("1902-01-01 00:00:00");
                if(end.before(begin)&&end.after(cdate)){
                    return new ModelVo(StaticKeys.OH_FALSE, "长嘱结束时间不能大于开始时间！");
                }
            }else{
                vafMap.put("vaf37","1899-12-30 00:00:00");
            }

            //为审核时间赋值
            if(ltype>=1&&ltype<=2&&"1".equals(pvalue)&&1==fchange&&(!"1".equals(para203)||("1".equals(para203)&&!bce01a.equals(lbce01)))){
                vafMap.put("vaf71","1899-12-30 00:00:00");
            }else{
                vafMap.put("vaf71",ldate);
            }
            vafMap.put("vaf38","1899-12-30 00:00:00");  //上次执行时间默认给值
            vafMap.put("vaf51",0);  //申请ID
            vafMap.put("vaf52",0);  //上传标识
            vafMap.put("vaf54",0);  //忽略打印 0-否 1-忽略
            vafMap.put("vaf61",MapUtils.getInteger(vafMap,"vaf61",1));  //首日执行次数
            vafMap.put("vaf62",MapUtils.getInteger(vafMap,"vaf61",1));  //末日执行次数
//            if (lacf01 == 2 && ("1".equals(bda01) || "2".equals(bda01) || ("T".equals(bda01) && vaf32 == 1))) {
//                String key = cbmid + vaf59 + vaf11;
//                Integer cn = rmap.get(key);
//                if (cn != null) {
//                    rmap.put(key, cn+1);
//                } else {
//                    rmap.put(key, 1);
//                }
//            }
//            if(rmap!=null&&rmap.keySet().size()>1){
//                return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "本组医嘱中存在医嘱期效不一样的情况，请检查.");
//            }
        }

        return null;
    }

    //获取医嘱提醒信息
    private List<Map<String,Object>> getTmpVbz(Map<String,Object> map){
        List<Map<String,Object>> tmpVAF = (List<Map<String,Object>>)map.get("tmpVAF");
        List<Map<String,Object>> tmpCBM = (List<Map<String,Object>>)map.get("tmpCBM");
        Iterator<Map<String,Object>> it = tmpVAF.iterator();
        Iterator<Map<String,Object>> it2 = tmpCBM.iterator();
        Integer lacf01 = MapUtils.getInteger(map,"lacf01");
        List<Map<String,Object>> vbzList = new ArrayList<Map<String,Object>>();
        while(it.hasNext()){
            Map<String,Object> vafMap = it.next();
            Long cbm01a = MapUtils.getLong(vafMap,"cbm01",0l);
            Integer vaf06 = MapUtils.getInteger(vafMap,"vaf06");
            Integer vaf11 = MapUtils.getInteger(vafMap,"vaf11");
            Long vaa01 = MapUtils.getLong(vafMap,"vaa01");
            Integer bck01a = MapUtils.getInteger(vafMap,"bck01a",0);
            Integer vaf35 = MapUtils.getInteger(vafMap,"vaf35",0);
            String bda01 = MapUtils.getString(vafMap,"bda01","");
            Long vaf01a = MapUtils.getLong(vafMap,"vaf01a",-1l);
            Long vaf01 = MapUtils.getLong(vafMap,"vaf01",-1l);
            Integer vaf32 = MapUtils.getInteger(vafMap,"vaf32",-1);
            while(it2.hasNext()){
                Map<String,Object> cbmMap = it2.next();
                Long cbm01b = MapUtils.getLong(cbmMap,"cbm01",-1l);
                if(cbm01a.longValue()==cbm01b.longValue()){
                    if(vaf01.longValue()>0&&vaf32==0&&bda01.charAt(0)<'A'||(bda01.charAt(0)>='A'&&vaf01a.longValue()==0l)) {
                        Map<String, Object> vbzMap = new HashMap<String, Object>();
                        String vaa04 = MapUtils.getString(cbmMap, "vaa04", "");
                        String vaa05 = MapUtils.getString(cbmMap, "vaa05", "");
                        String bcq04 = MapUtils.getString(cbmMap, "bcq04", "");
                        String uuid = UUID.randomUUID().toString();
                        vbzMap.put("vbz01",uuid);
                        vbzMap.put("vaf01", vaf01);
                        vbzMap.put("acf01", lacf01);
                        vbzMap.put("vaa07", vaf06);
                        vbzMap.put("vaf11", vaf11);
                        vbzMap.put("vaa01", vaa01);
                        vbzMap.put("bck01a", bck01a);
                        vbzMap.put("vaf35", vaf35);
                        vbzMap.put("vaa04", vaa04);
                        vbzMap.put("vaa05", vaa05);
                        vbzMap.put("vaf10", 1);
                        vbzMap.put("bcq04", bcq04);
                        vbzList.add(vbzMap);
                        return vbzList;
                    }
                }
            }
        }
        return null;
    }
    /**
     * 新开医嘱(住院) Clinic_VAF1_Insert
     *
     * @param map
     * @return
     * @throws Exception
     */
    public ModelVo insertClinicVAF2(Map map) throws Exception {
        ModelVo mo = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        String ldate = sdf.format(new Date());
        map.put("ldate", ldate);
        Long lbce01 = MapUtils.getLong(map,"lbce01"); //员工ID
        String lbce03 = MapUtils.getString(map,"lbce03");  //员工姓名
        String lxml = MapUtils.getString(map,"lxml"); //获取医嘱相关json信息字符串
        Integer lacf01 = MapUtils.getInteger(map,"lacf01");
        Integer fasong = MapUtils.getInteger(map,"fasong",0);
        Map map1 = new HashMap();
        
        if(StringUtils.isBlank(lxml)){
            return new ModelVo(StaticKeys.OH_FALSE, "提交信息错误，医嘱相关信息为空！");
        }
        JSONObject job = JSONObject.fromObject(lxml);
        if(job==null||job.isEmpty()){
            return new ModelVo(StaticKeys.OH_FALSE, "提交信息错误，医嘱相关信息格式不正确，请检查！");
        }
        List<Map<String,Object>> tmpCBM = getCviTmpCBM(job, lbce01, lbce03);  // 获取医嘱单信息
        if (tmpCBM==null||tmpCBM.size() == 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "提交信息错误，医嘱单信息不能为空！");
        }
        List<Map<String,Object>> tmpVBQ = getCviTmpVBQ(job); // 获取病人诊疗申请单
        
        Map<String,List> Rmap = getCviTmpVAF(job,tmpCBM,tmpVBQ,map);
        List<Map<String,Object>> tmpVAF = Rmap.get("TmpVAF"); // 获取医嘱内容信息
        tmpVBQ = Rmap.get("tempVBQ");
        tmpCBM = Rmap.get("tmpCBM");
        if (tmpVAF.size() == 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "提交信息错误，医嘱内容信息不能为空！");
        }
        List tmpVAO = getCviTmpVAO(job,tmpCBM); // 获取病人诊断信息
        List tmpVAX = getCviTmpVAX(job);// 获取病人手术人员信息
        List tmpVBF = getCviTmpVBF(tmpVAX, tmpVAF);// 更新病人手术人员信息，获取病人医嘱附件
        ModelVo mvo = validateTmpVAF(tmpVAF,map);//后台校验医嘱内容
        if(mvo!=null){
            return mvo;
        }
        // 若是修改医嘱则先删除修改的医嘱单
        Integer lmode = MapUtils.getInteger(map,"lmode");// 0:新增 1：修改 2=复诊预约计划
        Long lcbm01a = MapUtils.getLong(map,"lcbm01a",0l);
        if (lmode==1 && (lcbm01a > 0)){
            mo = delclinicAdviceCBM01(map);
            if (StaticKeys.OH_FALSE.equals(mo.getResult())){
                return mo;
            }
        }

        map.put("tmpCBM", tmpCBM);
        map.put("tmpVAF",tmpVAF);
        map.put("tmpVBQ",tmpVBQ);
        map.put("tmpVAO",tmpVAO);
        map.put("tmpVAX",tmpVAX);
        map.put("tmpVBF",tmpVBF);
        
        insertCviCBM(map);// 插入医嘱单信息
        insertCviVbq(map);// 插入检查申请单信息
        insertCviVaf(map);// 插入医嘱内容记录信息
        insertCviVao(map);// 插入病人诊断信息
        insertCviVbg(map);// 插入病人医嘱状态信息
        updateCviBdj(map);// 更新私人诊疗项目信息
        insertCviBdj(map); // 插入私人诊疗项目信息
        insertCviVax(map);// 插入医嘱手术人员信息和医嘱附件信息

        if (lmode!=2){updateCviVcj1(map);} //更新或修改挂号附表
        if(lacf01==2){  //插入医嘱新开提醒（住院）
            List<Map<String,Object>> tmpVBZ = getTmpVbz(map);
            if(tmpVBZ!=null&&tmpVBZ.size()>0) {
                map.put("tmpVBZ", tmpVBZ);
                doctorordernewDao.insert("Doctorordernew.insertCviVBZ", map);
            }
        }
        
        if(lmode==1 && (lcbm01a > 0)) {
            mo = new ModelVo(StaticKeys.OH_SUCCESS, "医嘱修改成功！");
        }else{
            mo = new ModelVo(StaticKeys.OH_SUCCESS, "医嘱保存成功！");
        }
        mo.setUserdata((tmpCBM.get(0)).get("cbm01").toString());
        if(fasong==1){
        	String para422 = (String) doctorordernewDao.sysParamValue().get("para422");
        	int j = 0;
        	String lXml = "{\"VAF1\":[";
        	String VAFID = "";
        	String vaf06 = "";
        	if(tmpVAF.size()>0){
        		int vafsize = tmpVAF.size();
        		
        		for(int i=0;i<vafsize;i++){
        			int vaf11 = MapUtils.getInteger(tmpVAF.get(i),"vaf11",0);
        			int vaf32 = MapUtils.getInteger(tmpVAF.get(i),"vaf32",0);
        			String bda01 = MapUtils.getString(tmpVAF.get(i),"bda01","");
        			int bbx01 = MapUtils.getInteger(tmpVAF.get(i),"bbx01",0);
        			int rownr = MapUtils.getInteger(tmpVAF.get(i),"rownr",0);
        			Long vaf01a = MapUtils.getLong(tmpVAF.get(i),"vaf01a",0l);
        			Integer bbx13int =  (Integer) doctorordernewDao.queryToObject("Doctorordernew.selectbbx13", bbx01);
        			
        			if(bda01.equals("Z") && bbx13int>0){
        				continue;
        			}
        			if(para422.equals("1") && (!bda01.equals("L")&&!bda01.equals("E"))){
        				continue;
        			}
        			if((bda01.equals("T")||bda01.equals("1")||bda01.equals("2"))){
        				if(bda01.equals("T")){
        					if(vaf11==2 && vaf32==0 && rownr==0){
            					Long vaf01 = MapUtils.getLong(tmpVAF.get(i),"vaf01",0l);
                				Long vaa01 = MapUtils.getLong(tmpVAF.get(i),"vaa01",0l);
                				String vaf061 = MapUtils.getString(tmpVAF.get(i),"vaf06");
                				int bck01b = MapUtils.getInteger(tmpVAF.get(i),"bck01b",0);
                				int vaf10 = MapUtils.getInteger(tmpVAF.get(i),"vaf10",0);
                				String vaf55 = MapUtils.getString(tmpVAF.get(i),"vaf55","");
                				String vaf23 = MapUtils.getString(tmpVAF.get(i),"vaf23","");
                				String vaf30 = MapUtils.getString(tmpVAF.get(i),"vaf30","");
                				
                				if(j>0){
                					lXml+=",";
                					VAFID+=",";
                				}
                				VAFID+=vaf01;
                				vaf06=vaf061;
                				lXml+="{\"vaf01\":\""+vaf01+"\",\"vaa01\":\""+vaa01+"\",\"bck01b\":\""+bck01b+"\",\"vaf11\":"+vaf11+",\"vaf10\":\""+vaf10+"\",\"vaf55\":\""+vaf55+"\",\"vaf23\":\""+vaf23+"\",\"vaf30\":\""+vaf30+"\"}";
                				j++;
            				}
        				}else{
        					if(vaf11==2){
        						Long vaf01 = MapUtils.getLong(tmpVAF.get(i),"vaf01",0l);
                				Long vaa01 = MapUtils.getLong(tmpVAF.get(i),"vaa01",0l);
                				String vaf061 = MapUtils.getString(tmpVAF.get(i),"vaf06");
                				int bck01b = MapUtils.getInteger(tmpVAF.get(i),"bck01b",0);
                				int vaf10 = MapUtils.getInteger(tmpVAF.get(i),"vaf10",0);
                				String vaf55 = MapUtils.getString(tmpVAF.get(i),"vaf55","");
                				String vaf23 = MapUtils.getString(tmpVAF.get(i),"vaf23","");
                				String vaf30 = MapUtils.getString(tmpVAF.get(i),"vaf30","");
                				
                				if(j>0){
                					lXml+=",";
                					VAFID+=",";
                				}
                				VAFID+=vaf01;
                				vaf06=vaf061;
                				lXml+="{\"vaf01\":\""+vaf01+"\",\"vaa01\":\""+vaa01+"\",\"bck01b\":\""+bck01b+"\",\"vaf11\":"+vaf11+",\"vaf10\":\""+vaf10+"\",\"vaf55\":\""+vaf55+"\",\"vaf23\":\""+vaf23+"\",\"vaf30\":\""+vaf30+"\"}";
                				j++;
            				}
    					}

        			}else{        				
        				if(vaf01a==0 && vaf11==2 ){
        					Long vaf01 = MapUtils.getLong(tmpVAF.get(i),"vaf01",0l);
            				Long vaa01 = MapUtils.getLong(tmpVAF.get(i),"vaa01",0l);
            				String vaf061 = MapUtils.getString(tmpVAF.get(i),"vaf06");
            				int bck01b = MapUtils.getInteger(tmpVAF.get(i),"bck01b",0);
            				int vaf10 = MapUtils.getInteger(tmpVAF.get(i),"vaf10",0);
            				String vaf55 = MapUtils.getString(tmpVAF.get(i),"vaf55","");
            				String vaf23 = MapUtils.getString(tmpVAF.get(i),"vaf23","");
            				String vaf30 = MapUtils.getString(tmpVAF.get(i),"vaf30","");
            				
            				if(j>0){
            					lXml+=",";
            					VAFID+=",";
            				}
            				VAFID+=vaf01;
            				vaf06=vaf061;
            				lXml+="{\"vaf01\":\""+vaf01+"\",\"vaa01\":\""+vaa01+"\",\"bck01b\":\""+bck01b+"\",\"vaf11\":"+vaf11+",\"vaf10\":\""+vaf10+"\",\"vaf55\":\""+vaf55+"\",\"vaf23\":\""+vaf23+"\",\"vaf30\":\""+vaf30+"\"}";
            				j++;
        				}
        			}
        			
        		}
        	}
        	lXml+="]}";
        	if(j>0){
        		map1.put("vaf45", "");
        		map1.put("VAFID", VAFID);
        		map1.put("vaf06", vaf06);
        		map1.put("lUName", MapUtils.getString(map,"lbce03"));
        		map1.put("lBCE01", lbce01);
        		map1.put("lBCE01A", lbce01);
        		map1.put("lBCE01B", lbce01);
            	map1.put("lBCE02", MapUtils.getString(map,"lbce02"));
            	map1.put("lBCE03", MapUtils.getString(map,"lbce03"));
            	map1.put("lXml", lXml);
     	    	map1.put("lBCKxml", "{\"BCK1\":[]}");
     	    	map1.put("lSign", 6);
     	    	map1.put("lSend", 0);
     	    	mo.setMap(map1);
        	}       	
        }
        return mo;
    }

    public ModelVo selectMedOrderca(Map map)throws Exception{
        return MySqlUtil.packModelVo("Doctorordernew.7341",map,doctorordernewDao);
    }
    public ModelVo selectMedOrderrecid(Map map)throws Exception{
        return MySqlUtil.packModelVo("Doctorordernew.6428",map,doctorordernewDao);
    }
    public ModelVo selectOrdervaluation(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.6900",map,doctorordernewDao);
    }
    public ModelVo selectOrderlistvaluation(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1429",map,doctorordernewDao);
    }
    public ModelVo selectOrderlistvaluation2(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1428",map,doctorordernewDao);
    }
    public ModelVo selectOrderitemfee(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1762",map,doctorordernewDao);
    }
    public ModelVo selectOrderexerecord(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1021",map,doctorordernewDao);
    }
    public ModelVo selectOrdersummary(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.6435",map,doctorordernewDao);
    }
    public ModelVo selectSendDrugvaluation(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1035",map,doctorordernewDao);
    }
    public ModelVo selectSendedCNDrugvaluation(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1036",map,doctorordernewDao);
    }
    public ModelVo selectTempOrdervaluation(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1038",map,doctorordernewDao);
    }
    public ModelVo selectOperationcrew(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.7299",map,doctorordernewDao);
    }
    public ModelVo selectOperationvaludation(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1037",map,doctorordernewDao);
    }
    public ModelVo selectOperationsendrcd(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1020",map,doctorordernewDao);
    }
    public ModelVo selectShoushujijia(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1430",map,doctorordernewDao);
    }
    public ModelVo selectOrderitemfee2(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1431",map,doctorordernewDao);
    }
    public ModelVo selectJianchajijia(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.2006",map,doctorordernewDao);
    }
    public ModelVo selectDiagnosticrecords(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.754",map,doctorordernewDao);
    }
    public ModelVo selectDiseaseType(){
        return MySqlUtil.packModelVo("Doctorordernew.diseaseType",null,doctorordernewDao);
    }
    public ModelVo selectDiseaseDir(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.diseaseDir",map,doctorordernewDao);
    }
    public ModelVo selectDiagroottype(){
        return MySqlUtil.packModelVo("Doctorordernew.diagroottype",null,doctorordernewDao);
    }
    public ModelVo selectOrderitems(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1438",map,doctorordernewDao);
    }
    public ModelVo selectTreatItems(Map map, int currentPage, int pageSize){
        long btime = System.currentTimeMillis();
        ModelVo mo = new ModelVo();
        try {
            String lBEH01 = MapUtils.getString(map,"lBEH01","");
            Page pg = null;
            if(lBEH01.equals("8")){
                pg = doctorordernewDao.queryForPage("Doctorordernew.14391", map, currentPage, pageSize);
            }else if(lBEH01.equals("0")){
                map.put("lDate", DateUtils.getDateStr(new Date())+" 23:59:59");
                pg = doctorordernewDao.queryForPage("Doctorordernew.1061", map, currentPage, pageSize);
            }else{
                pg = doctorordernewDao.queryForPage("Doctorordernew.1439", map, currentPage, pageSize);
            }

            mo.setList(pg.getList());
            mo.setResult(StaticKeys.OH_SUCCESS);
            mo.setTotal(pg.getTotalNumber());
            mo.setRows(pg.getList());
        } catch (Exception e) {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        long etime = System.currentTimeMillis();
        System.out.println((etime-btime)+"秒");
        return mo;
    }
    public ModelVo checkDepHasOpera(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.7298",map,doctorordernewDao);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public ModelVo medTreeToDetail(Map map, int currentPage, int pageSize)
            throws Exception{
        // 获取参数
        //Map params = getMttdParams();
        // 获取当前时间
        String lDate = DateUtils.getDateStr(new Date()) + " 23:59:59.999";
        // 获取检索规则
        //String aParamno = params.get("aparamno").toString();
        Integer lACF01 = MapUtils.getInteger(map,"lACF01");
        Integer bdm01 = MapUtils.getInteger(map,"bdm01");
        String gparam60 = MapUtils.getString(map,"gparam60");
        String aparam1 = MapUtils.getString(map,"aparam1");
        String aParamno = MapUtils.getString(map,"aParamno");
//        long b1 = System.currentTimeMillis();
        // 参数整合
        //map.putAll(params);
//        HashMap<String, Object> temp1 = new HashMap<String,Object>();
//        temp1.put("productid", 9999);
//        temp1.put("programid", 9999);
//        temp1.put("paramno", 60);
//        map.put("gparam60", doctorordernewDao.getSysParamValue(temp1));
//        HashMap<String, Object> temp2 = new HashMap<String,Object>();
//        temp2.put("productid", 9999);
//        temp2.put("programid", 9999);
//        temp2.put("paramno", 1);
//        map.put("aparam1", doctorordernewDao.getSysParamValue(temp2));
//        HashMap<String, Object> temp3 = new HashMap<String,Object>();
//        temp3.put("productid", 9999);
//        temp3.put("programid", 9999);
//        temp3.put("paramno", 15);
//        String aParamno = doctorordernewDao.getSysParamValue(temp3);
        map.put("aParamno",aParamno);    //此处暂时按默认规则检索 后期需要更改规则再进行优化
        map.put("gparam60",aParamno);
        map.put("aparam1",aparam1);
        map.put("lDate", lDate);
//        long e1 = System.currentTimeMillis();
//        System.out.println("参数查询花费："+(e1-b1));
        Page pg = null;
//        List list = null;
        if(bdm01==8){
        	long b0 = System.currentTimeMillis();
            // 按默认规则检查
            pg = getaParamno8List(map,currentPage,pageSize);
            long e0 = System.currentTimeMillis();
            System.out.println("aParamno0查询数据花费："+(e0-b0));
        }else{
        	if ("0".equals(aParamno))
            {
                long b0 = System.currentTimeMillis();
                // 按默认规则检查
                pg = getaParamno0List(map,currentPage,pageSize);
                long e0 = System.currentTimeMillis();
                System.out.println("aParamno0查询数据花费："+(e0-b0));
            }
            else
            {
                if ("3".equals(aParamno))
                {
                    if (lACF01.equals(1))
                    {
                        pg = getaParamnoe1List(map,currentPage,pageSize);
                    }
//                    long b2 = System.currentTimeMillis();
                    if (lACF01.equals(2))
                    {
                        pg = getaParamnoe2List(map,currentPage,pageSize);
                    }
//                    long e2 = System.currentTimeMillis();
//                    System.out.println("aParamno3查询数据花费："+(e2-b2));
                }
                else
                {
                    pg = getaParamnoeList(map,currentPage,pageSize);
                }
            }
        }
        
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS, "");
        mo.setRows(pg.getList());
        mo.setList(pg.getList());
        mo.setTotal(pg.getTotalNumber());
        mo.setPage(currentPage);
        mo.setRecords(pg.getTotalNumber());
        mo.setTotalPage(pg.getTotalPage());
        return mo;
    }
    private Page getaParamno0List(Map map, int currentPage, int pageSize)
            throws Exception
    {
    	 return doctorordernewDao.getaParamno0List(map, currentPage, pageSize);
    }
    private Page getaParamno8List(Map map, int currentPage, int pageSize)
            throws Exception
    {
    	 return doctorordernewDao.getaParamno8List(map, currentPage, pageSize);
    }
    private Page getaParamnoe1List(Map map, int currentPage, int pageSize)
            throws Exception
    {
        Page pg = doctorordernewDao.getaParamnoe1List(map, currentPage, pageSize);
        return pg;
    }
    private Page getaParamnoe2List(Map map, int currentPage, int pageSize)
            throws Exception
    {
        return doctorordernewDao.getaParamnoe2List(map, currentPage, pageSize);
    }
    private Page getaParamnoeList(Map map, int currentPage, int pageSize)
            throws Exception
    {
        return doctorordernewDao.getaParamnoeList(map, currentPage, pageSize);
    }
//    private List getaParamno0List(Map map)throws Exception{
//        return doctorordernewDao.getaParamno0List(map);
//    }
//    private List getaParamnoe1List(Map map)throws Exception{
//        return doctorordernewDao.getaParamnoe1List(map);
//    }
//    private List getaParamnoe2List(Map map)throws Exception{
//        return doctorordernewDao.getaParamnoe2List(map);
//    }
//    private List getaParamnoeList(Map map)throws Exception{
//        return doctorordernewDao.getaParamnoeList(map);
//    }
    public ModelVo selectDrupguige(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.744",map,doctorordernewDao);
    }
    public ModelVo selectDrupway(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.drugway",map,doctorordernewDao);
    }
    public ModelVo selectOperationpro(Map map,int pageno,int pagesize){
        long bg = System.currentTimeMillis();
        ModelVo mv = MySqlUtil.packModelVoPage("Doctorordernew.operationpro",map,pageno,pagesize,doctorordernewDao);
        long ed = System.currentTimeMillis();
        System.out.println((ed-bg)+"毫秒");
        return mv;
    }
    public ModelVo selectAnaesthesiaItem(){
        return MySqlUtil.packModelVo("Doctorordernew.anaesthesiaItem",null,doctorordernewDao);
    }
    public ModelVo selectSampletype(){
        return MySqlUtil.packModelVo("Doctorordernew.sampletype",null,doctorordernewDao);
    }
    public ModelVo selectFootnote(){
        return MySqlUtil.packModelVo("Doctorordernew.footnote",null,doctorordernewDao);
    }
    public ModelVo selectDrugcompro(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.7303",map,doctorordernewDao);
    }
    public ModelVo selectFriedtype(){
        return MySqlUtil.packModelVo("Doctorordernew.friedtype",null,doctorordernewDao);
    }
    /* scriptId(1756) 检验/手术/治疗其他项目计价信息 */
    public ModelVo selectJijia(Map map)throws Exception{
        String abc02 = (String)doctorordernewDao.queryToObject("Doctorordernew.1756_1",map);
        map.put("ABC02",abc02==null?"":abc02);
        return MySqlUtil.packModelVo("Doctorordernew.1756_2",map,doctorordernewDao);
    }
    /* scriptId(1761) 检查项目计价信息 */
    public ModelVo selectJijia2(Map map)throws Exception{
        String abc02 = (String)doctorordernewDao.queryToObject("Doctorordernew.1761_1",map);
        map.put("ABC02",abc02==null?"":abc02);
        return MySqlUtil.packModelVo("Doctorordernew.1761_2",map,doctorordernewDao);
    }
    /* scriptId(7326) 卫生材料计价信息 */
    public ModelVo selectJijia3(Map map)throws Exception{
        String abc02 = (String)doctorordernewDao.queryToObject("Doctorordernew.7326_1",map);
        map.put("ABC02",abc02==null?"":abc02);
        return MySqlUtil.packModelVo("Doctorordernew.7326_2",map,doctorordernewDao);
    }
    public ModelVo selectBbxinfo(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.getBbxinfo",map,doctorordernewDao);
    }
    /* scriptId(null) 获取执行频次 */
    public ModelVo selectExefreq(Map map){
        Integer aBDI12 = MapUtils.getInteger(map,"aBDI12",1);
        if(aBDI12.intValue()==1){
            aBDI12 = 2;
        }else{
            aBDI12 = 1;
        }
        map.put("aBDI12",aBDI12);
        return MySqlUtil.packModelVo("Doctorordernew.getExefreq",map,doctorordernewDao);
    }

    public ModelVo selectExebck(Map map)throws Exception{
        Map<String,Object> rmap = (Map<String,Object>)doctorordernewDao.queryToObject("Doctorordernew.getExebck_001",map);
        if(rmap==null||rmap.size()==0){
            return MySqlUtil.packModelVo("Doctorordernew.getExebck_002",map,doctorordernewDao);
        }else{
            List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
            list.add(rmap);
            ModelVo mo = new ModelVo();
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
            mo.setTotal(list.size());
            mo.setRows(list);
            return mo;
        }
    }
    public ModelVo getPishi(Map map)throws Exception{
        Map<String,Object> rmap = (Map<String,Object>)doctorordernewDao.queryToObject("Doctorordernew.getPishi",map);
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        list.add(rmap);
        ModelVo mo = new ModelVo();
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(list.size());
        mo.setRows(list);
        return mo;
    }
    public ModelVo selectHygiMaterBck(Map map)throws Exception{
        Long bck01 = (Long)doctorordernewDao.queryToObject("Doctorordernew.getHygiMaterBck_001",map);
        bck01 = bck01==null?0:bck01;
        if(bck01==0){
            ModelVo mo = new ModelVo();
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("执行科室配置有误,请与管理员联系!");
            return mo;
        }else{
            map.put("bck01",bck01);
            return MySqlUtil.packModelVo("Doctorordernew.getHygiMaterBck_002",map,doctorordernewDao);
        }
    }
    public ModelVo selectDrupbck(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.getDrugbck",map,doctorordernewDao);
    }


    public ModelVo selectTreatList(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.1686",map,doctorordernewDao);
    }
    public ModelVo selectYishi(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.916",map,doctorordernewDao);
    }
    public ModelVo selectDrugDest(){
        return MySqlUtil.packModelVo("Doctorordernew.drugdest",null,doctorordernewDao);
    }
    public ModelVo selectOprationRank(){
        return MySqlUtil.packModelVo("Doctorordernew.oprationrank",null,doctorordernewDao);
    }

    public ModelVo selectCnExeBck(Map map)throws Exception{
       String param = doctorparameterBo.getSysValue(9999,9999,15);
       param=(param==null?"0":param);
       if("0".equals(param)){
           String bdn01 = (String)doctorordernewDao.queryForExtObject("Doctorordernew.6431_001",map);
           map.put("bdn01",StringUtils.isBlank(bdn01)?'0':bdn01);
           return MySqlUtil.packModelVo("Doctorordernew.6431_002",map,doctorordernewDao);
       }else{
           return MySqlUtil.packModelVo("Doctorordernew.6431_003",map,doctorordernewDao);
       }

    }
    public ModelVo selectWeishengJijia(Map map){
        return MySqlUtil.packModelVo("Doctorordernew.7708",map,doctorordernewDao);
    }
    public Map selectsolrlist(Integer bck01,Integer corporationid,String dbname,Integer type)throws Exception{
    	return doctorordernewDao.selectsolrlist(bck01,corporationid,dbname,type);
    }
    public ModelVo delete6433(Map map)throws Exception{
    	 ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS, "删除成功!");
    	doctorordernewDao.delete("Doctorordernew.6433",map);
    	return mo;
    }
    public ModelVo update6433(Map map)throws Exception{
	   	 ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS, "更新成功!");
	   	doctorordernewDao.update("Doctorordernew.update6433",map);
	   	return mo;
   }
   //会诊完成
    public ModelVo NurseSetVCL1VCL17(Map map)throws Exception{
        Integer countvcl1 = (Integer)doctorordernewDao.queryForExtObject("Doctorordernew.countvcl1", map);
        if (countvcl1 <= 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "不存在此病人会诊信息！");
        }
        Integer countvcl2 = (Integer)doctorordernewDao.queryForExtObject("Doctorordernew.countvcl2", map);
        if (countvcl2 <= 0) {
            return new ModelVo(StaticKeys.OH_FALSE, "此病人已经完成会诊！");
        }

        doctorordernewDao.update("Doctorordernew.updatevcl",map);
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS, "更新成功!");
        return mo;

    }
}
